//
//  DynamicColumnFieldCore+DropDownData.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 2017/9/29.
//  Copyright © 2017年 com.xtion.crm. All rights reserved.
//

#import "DynamicColumnFieldCore+DropDownData.h"
#import "DynamicColumnFieldCore+Internal.h"

@implementation DynamicColumnFieldCore (DropDownData)

- (void)initSingleSelect:(NSArray*)needLoadSingleSelect
{
    DynamicColumnFieldViewType vclType = [_dataSource typeOfDynamicColumnFieldCore:self];
    
    if (vclType == DynamicColumnFieldViewTypeReview)
    {
        return;
    }
    
    if (_newSingleSelect == nil)
    {
        _newSingleSelect = [NSMutableDictionary new];
    }
    
    for(FieldDescript *fieldDescript in needLoadSingleSelect)
    {
        [_manager getDictionaryList:fieldDescript completion:^(NSInteger nResult, NSArray *arList) {
            if(nResult == YES)
            {
                [_newSingleSelect setObject:arList forKey:fieldDescript.fieldLabel];
                
                for(SingleSelectInfo *item in arList)
                {
                    id value = [self valueForFieldDescript:fieldDescript];
                    
                    BOOL equal = ([item.key isEqualToString:[NSString stringWithFormat:@"%@",value]]);
                    if(equal)
                    {
                        ExpandDynamicCell *cell = (ExpandDynamicCell *)[_gtable cellWithTag:fieldDescript.fieldName];
                        if([cell isMemberOfClass:[DropDownGroupTableViewCell class]])
                        {
                            ((DropDownGroupTableViewCell*)cell).text = item.value;
                        }
                        else if([cell isMemberOfClass:[DropDownTextGroupTableViewCell class]])
                        {
                            ((DropDownTextGroupTableViewCell*)cell).text = item.value;
                        }
                    }
                }
            }
        }];
    }
}
@end
